package com.ruoyi.network.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.network.domain.TargetEvent;
import com.ruoyi.network.domain.TargetPeople;
import com.ruoyi.network.mapper.TargetEventMapper;
import com.ruoyi.network.mapper.TargetPeopleMapper;
import com.ruoyi.network.service.INetworkDealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 11975
 */
@Service
public class NetworkDealServiceImpl implements INetworkDealService {

    @Autowired
    TargetPeopleMapper peopleMapper;

    @Autowired
    TargetEventMapper eventMapper;

    @Override
    public List<TargetPeople> getTargetPeopleList(TargetPeople targetPeople) {
        QueryWrapper<TargetPeople> wrapper = buildTargetPeople(targetPeople);
        return peopleMapper.selectList(wrapper);
    }

    @Override
    public List<TargetEvent> getTargetEventList(TargetEvent targetEvent) {
        QueryWrapper<TargetEvent> wrapper = buildTargetEvent(targetEvent);
        return eventMapper.selectList(wrapper);
    }

    @Override
    public IPage<TargetEvent> getEventList(TargetEvent event) {
        QueryWrapper<TargetEvent> wrapper = buildTargetEvent(event);
        IPage<TargetEvent> page = new Page<>(event.getPageNum(), event.getPageSize());
        return eventMapper.selectPage(page,wrapper);
    }

//    /**
//     * 查询人物信息
//     * @param targetPeople 人物
//     * @return queryWrapper
//     */
//    private QueryWrapper<TargetPeople> dealNetworkEquip(Net){
//        QueryWrapper<TargetPeople> wrapper = new QueryWrapper<>();
//        if (targetPeople != null) {
//            if (targetPeople.getUserId() != null) {
//                wrapper.eq("user_id", targetPeople.getUserId());
//            }
//            if (StringUtils.isNotBlank(targetPeople.getUserName())) {
//                wrapper.like("user_name", targetPeople.getUserName());
//            }
//            if (StringUtils.isNotBlank(targetPeople.getForeignName())) {
//                wrapper.like("foreign_name", targetPeople.getForeignName());
//            }
//            if (StringUtils.isNotBlank(targetPeople.getAlias())) {
//                wrapper.like("foreign_name", targetPeople.getAlias());
//            }
//            if (StringUtils.isNotBlank(targetPeople.getShipCountry())) {
//                wrapper.like("ship_country", targetPeople.getShipCountry());
//            }
//        }
//        return wrapper;
//    }

    /**
     * 查询人物信息
     * @param targetPeople 人物
     * @return queryWrapper
     */
    private QueryWrapper<TargetPeople> buildTargetPeople(TargetPeople targetPeople){
        QueryWrapper<TargetPeople> wrapper = new QueryWrapper<>();
        if (targetPeople != null) {
            if (targetPeople.getUserId() != null) {
                wrapper.eq("user_id", targetPeople.getUserId());
            }
            if (StringUtils.isNotBlank(targetPeople.getUserName())) {
                wrapper.like("user_name", targetPeople.getUserName());
            }
            if (StringUtils.isNotBlank(targetPeople.getForeignName())) {
                wrapper.like("foreign_name", targetPeople.getForeignName());
            }
            if (StringUtils.isNotBlank(targetPeople.getAlias())) {
                wrapper.like("foreign_name", targetPeople.getAlias());
            }
            if (StringUtils.isNotBlank(targetPeople.getShipCountry())) {
                wrapper.like("ship_country", targetPeople.getShipCountry());
            }
        }
        return wrapper;
    }

    /**
     * 查询事件信息
     * @param targetEvent 事件
     * @return queryWrapper
     */
    private QueryWrapper<TargetEvent> buildTargetEvent(TargetEvent targetEvent){
        QueryWrapper<TargetEvent> wrapper = new QueryWrapper<>();
        if (targetEvent != null){
            if (targetEvent.getEventId() != null){
                wrapper.eq("event_id",targetEvent.getEventId());
            }
            if (StringUtils.isNotBlank(targetEvent.getEventName())){
                wrapper.like("event_name",targetEvent.getEventName());
            }
            if (StringUtils.isNotBlank(targetEvent.getEventAlias())){
                wrapper.like("event_alias",targetEvent.getEventAlias());
            }
            if (StringUtils.isNotBlank(targetEvent.getEventPower())){
                wrapper.like("event_power",targetEvent.getEventPower());
            }
            if (StringUtils.isNotBlank(targetEvent.getEventTarget())){
                wrapper.like("event_target",targetEvent.getEventTarget());
            }
            if (StringUtils.isNotBlank(targetEvent.getEventTarget())){
                wrapper.ge("event_occur_time", targetEvent.getStartTime())
                        .le("event_occur_time", targetEvent.getEndTime());
            }
        }
        return wrapper;
    }


}
